package com.yixing.tech.system.po;

import com.yixing.tech.common.base.BasePO;
import com.yixing.tech.common.enums.Status;
import com.yixing.tech.common.enums.UserType;
import com.yixing.tech.common.security.AuthenticationUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Collection;
import java.util.Collections;

import static com.yixing.tech.common.security.SecurityConstant.NO;
import static com.yixing.tech.common.security.SecurityConstant.YES;

/**
 * @author yixing tech
 * at 2021/12/15
 * describe：
 */
@Data
@Document(collection = "user")
@Accessors(chain=true)
@NoArgsConstructor
@AllArgsConstructor
public class SystemUser extends BasePO implements AuthenticationUser {
    private String name;
    @Indexed(unique=true)
    private String loginName;
    private String password;
    private String phone;
    private Role role;
    //TODO 改 确定含义
    private Role selfRole;
    private UserType type;
    private Integer status = Status.def.ordinal();
    private Boolean isSuper = false;
    private Boolean isAdmin;
    private String headPic;
    private String headPicUrl;
    private String desc;
    private String code;
    private String email;
    private String sessionKey;
    private String unionId;
    @Indexed
    private Department department;

    /**
     * 用户id
     */
    @Override
    public String getUserId() {
        return getId();
    }

    /**
     * Returns the username used to authenticate the user. Cannot return
     * <code>null</code>.
     *
     * @return the username (never <code>null</code>)
     */
    @Override
    public String getUsername() {
        return getLoginName();
    }

    /**
     * 权限集合
     */
    @Override
    public Collection<String> getPermissions() {
        return Collections.emptyList();
    }

    /**
     * 是否启用。1：启用，0：未启用
     */
    @Override
    public Integer getIsEnabled() {
        return YES;
    }

    /**
     * 账号是否过期，1：已经过期，0：未过期
     */
    @Override
    public Integer getIsExpired() {
        return NO;
    }

    /**
     * 账号是否被锁，1：被锁，0：未被锁
     */
    @Override
    public Integer getIsLocked() {
        return NO;
    }

    /**
     * 用户的凭证是否过期。1：已经过期，0：未过期
     */
    @Override
    public Integer getIsCredentialsExpired() {
        return NO;
    }

    /**
     * 是否超管
     */
    @Override
    public boolean isSuper() {
        return isSuper;
    }
}
